In this Application we have to show the working of MDI Form and their various Properties with the help of an example. Choose a New Project and Name as MDISample, Next Right Click on the right hand side of MDISample and Click on ADD Option then Click on ADD item, then chooses an Option MDIParent Form as shown below as shown in arrow.

As we click on MDIParent form you will see Below or we can use menus as well as ToolStrip task with the help of control as shown Below with the help of an Arrow.

As in the above figure we can see all the functionalities as normal notepad as vertical tiles, Horizontal Tiles, cascade, close all, Arrange Icons etc.
The Code Snippet as shown below
public partial class MDIParent1 : Form
{
private int childFormNumber = 0;//Initializing childformno as 0.
public MDIParent1()
{
InitializeComponent();
}
private void ShowNewForm(object sender, EventArgs e)
{
Form childForm = new Form();//Creating Object of Form
childForm.MdiParent = this;
childForm.Text = "Window " + childFormNumber++;
childForm.Show();
}
private void OpenFile(object sender, EventArgs e)
{
//Creating an object of openFileDialog and checking the open file into the same form.
OpenFileDialog openFileDialog = new OpenFileDialog();
//openning the file as initial directory
openFileDialog.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.Personal);
openFileDialog.Filter = "Text Files (*.txt)|*.txt|All Files (*.*)|*.*";
if (openFileDialog.ShowDialog(this) == DialogResult.OK)
{
string FileName = openFileDialog.FileName;
}
}
private void SaveAsToolStripMenuItem_Click(object sender, EventArgs e)
{ //Creating an object of savefile dialog
SaveFileDialog saveFileDialog = new SaveFileDialog();
//saving the file in a initial directory
saveFileDialog.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.Personal);
saveFileDialog.Filter = "Text Files (*.txt)|*.txt|All Files (*.*)|*.*";
//Checking condition for save Dialog box
if (saveFileDialog.ShowDialog(this) == DialogResult.OK)
{
string FileName = saveFileDialog.FileName;
}
}
private void ExitToolsStripMenuItem_Click(object sender, EventArgs e)
{ //Closing the application
this.Close();
}
private void CutToolStripMenuItem_Click(object sender, EventArgs e)
{
}
private void CopyToolStripMenuItem_Click(object sender, EventArgs e)
{
}
private void PasteToolStripMenuItem_Click(object sender, EventArgs e)
{
}
private void ToolBarToolStripMenuItem_Click(object sender, EventArgs e)
{
toolStrip.Visible = toolBarToolStripMenuItem.Checked;
}
private void StatusBarToolStripMenuItem_Click(object sender, EventArgs e)
{
statusStrip.Visible = statusBarToolStripMenuItem.Checked;
}
private void CascadeToolStripMenuItem_Click(object sender,EventArgs e)
{//for cascading
LayoutMdi(MdiLayout.Cascade);
}

private void TileVerticalToolStripMenuItem_Click(object sender, EventArgs e)
{//for Tile verticle
LayoutMdi(MdiLayout.TileVertical);
}

private void TileHorizontalToolStripMenuItem_Click(object sender, EventArgs e)
{//For Horizontal
LayoutMdi(MdiLayout.TileHorizontal);
}

private void ArrangeIconsToolStripMenuItem_Click(object sender, EventArgs e)
{//for Arrange icons
LayoutMdi(MdiLayout.ArrangeIcons);
}

private void CloseAllToolStripMenuItem_Click(object sender, EventArgs e)
{
foreach (Form childForm in MdiChildren)
{//closing Form
childForm.Close();
}
}
The Output of the code is shown as

Leave Comment
2 Comments